<style lang="less">
  .standard-price-version-line-add {
    .el-select{
      width: 100%;
    }
    .el-cascader{
      width: 100%;
    }
  }
</style>

<template>
  <el-dialog :modal-append-to-body="false" title="新增线路" :visible.sync="dialogVisible" size="tiny" class="standard-price-version-line-add">
    <el-form label-width="100px" ref="form" :model="form">
      <el-form-item label="线路名称"
                    :rules="{ type: 'array', required: true, message: '请选择地址', trigger: 'change' }"
                    prop="addressData">
        <address-select v-model="form.addressData"
                        placeholder="请选择地址"
                        change-on-select>
        </address-select>
      </el-form-item>
      <el-form-item label="运价类型" prop="lineType">
        <el-radio-group v-model="form.lineType">
          <el-radio class="radio" :label="112012002">直达</el-radio>
          <el-radio class="radio" :label="112012001">中转</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="运输方式"
                    :rules="{ type: 'number', required: true, message: '请运输方式', trigger: 'change' }"
                    prop="ageingType">
        <el-select v-model="form.ageingType"
                   filterable placeholder="请选择运输方式">
          <el-option
                     v-for="item in $store.getters.AGING_CLASSIFICATION"
                     :label="item.cnDictValname"
                     :key = "item.id"
                     :value="item.dictVal"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="时效范围"
                    :rules="{ type: 'string', required: true, message: '请输入时效范围', trigger: 'blur' }"
                    prop="ageingScope">
        <el-input v-model="form.ageingScope" placeholder="请输入时效范围"></el-input>
      </el-form-item>
      <el-form-item label="起步收费"
                    :rules="{ type: 'number', required: true, message: '请输入起步收费', trigger: 'blur' }"
                    prop="startingPrice">
        <el-input v-model.number="form.startingPrice" placeholder="请输入起步收费"></el-input>
      </el-form-item>
      <el-form-item label=" 备 注 " prop="description">
        <el-input type="textarea" v-model="form.description"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="createform" :loading="loading">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'StandardPriceVersionLineAdd',
  componentName: 'StandardPriceVersionLineAdd',
  data () {
    return {
      standardPriceVersionId: null,
      dialogVisible: false,
      loading: false,
      form: {
        id: null,
        addressData: [],
        province: null,
        city: null,
        county: null,
        ageingType: null,
        ageingScope: null,
        startingPrice: null,
        description: null,
        lineType: null
      }
    };
  },
  watch: {
    'form.addressData': {
      handler: function (val, oldVal) {
        let data = val.concat(null, null, null);
        this.form.province = data[0];
        this.form.city = data[1];
        this.form.county = data[2];
      },
      deep: true
    }
  },
  methods: {
    reset: function () {
      if (this.$refs.form) {
        this.$refs.form.resetFields();
      }
      this.$ue.resetObjNull(this.form);
    },
    show (o) {
      this.reset();
      if (o) {
        this.form.id = o.id;
        this.form.ageingType = o.ageingType;
        this.form.ageingScope = o.ageingScope;
        this.form.startingPrice = o.startingPrice;
        this.form.description = o.description;
        this.form.lineType = o.lineType;
        this.form.addressData = [o.province, o.city, o.county];
      } else {
        this.form.lineType = 112012002;
      }
      this.dialogVisible = true;
      this.loading = false;
    },
    hide () {
      this.loading = false;
      this.dialogVisible = false;
    },
    createform () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          let o = Object.assign({}, this.form);
          this.loading = true;
          this.$emit('comfirmSuccess', o);
        }
      });
    }
  },
  mounted () {}
};
</script>
